/*
 * #%L
 * SwiftUIDataAccessLayer
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2011 - 2012 Linkwithweb
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public 
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
/**
 * 
 */
package com.linkwithweb.products.swiftui.rowmapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;

import com.linkwithweb.products.swiftui.dataobject.FrameworkEvent;
import com.linkwithweb.products.swiftui.utils.DateUtils;

/**
 * DROP TABLE IF EXISTS `automata`.`frm_events`;
 * CREATE TABLE `automata`.`frm_events` (
 * `UNIQUE_KEY` int(11) NOT NULL AUTO_INCREMENT,
 * `EVENT_ID` varchar(127) NOT NULL,
 * `SCHEDULER_ID` varchar(127) NOT NULL,
 * `EVENT_NAME` varchar(127) NOT NULL,
 * `START_DATE` datetime NOT NULL,
 * `END_DATE` datetime NOT NULL,
 * `DETAILS` text NOT NULL,
 * `EVENT_LATITUDE` decimal(10,6),
 * `EVENT_LONGITUDE` decimal(10,6),
 * `EVENT_LOCATION_ADDRESS` VARCHAR(250),
 * `EVENT_USER_IDS` VARCHAR(250),
 * `IS_ACTIVE` tinyint(1) NOT NULL,
 * `IDENTIFIER` varchar(45) DEFAULT NULL,
 * `IDENTIFIER_ROLE` varchar(45) DEFAULT NULL,
 * `CREATED_BY` int(10) unsigned NOT NULL,
 * `CREATED_DATE` datetime NOT NULL,
 * `MODIFIED_BY` int(10) unsigned NOT NULL,
 * `MODIFIED_DATE` datetime NOT NULL,
 * PRIMARY KEY (`UNIQUE_KEY`)
 * ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 * 
 * @author ashwin kumar
 * 
 */
public class FrameworkEventRowMapper extends AbstractRowMapper {
	/*
	 * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet,
	 * int)
	 */
	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		FrameworkEvent frameworkEvent = new FrameworkEvent();
		frameworkEvent.setUniqueKey(rs.getLong("UNIQUE_KEY"));
		frameworkEvent.setEventDetails(rs.getString("DETAILS"));
		try {
			frameworkEvent.setEventEndDate(DateUtils.getInstance().getDate(rs.getString("END_DATE").replaceAll("\\.0", ""),"yyyy-MM-dd hh:mm:ss"));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			frameworkEvent.setEventStartDate(DateUtils.getInstance().getDate(rs.getString("START_DATE").replaceAll("\\.0", ""),"yyyy-MM-dd hh:mm:ss"));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		frameworkEvent.setEventId(rs.getString("EVENT_ID"));
		frameworkEvent.setEventLatitude(rs.getDouble("EVENT_LATITUDE"));
		frameworkEvent.setEventLocationAddress(rs.getString("EVENT_LOCATION_ADDRESS"));
		frameworkEvent.setEventLongitude(rs.getDouble("EVENT_LONGITUDE"));
		frameworkEvent.setEventName(rs.getString("EVENT_NAME"));
		frameworkEvent.setEventUserIds(rs.getString("EVENT_USER_IDS"));

		return mapDefaultColumns(frameworkEvent, rs);
	}

}
